package com.cn.kabalifeuser.ui.my.activity;

import com.cn.kabalifeuser.api.Api;
import com.cn.kabalifeuser.base.BasePresenter;
import com.cn.kabalifeuser.callback.CacheCallBack;
import com.cn.kabalifeuser.config.Constants;
import com.cn.kabalifeuser.ui.integral.bean.ShoppingMalListBean;
import com.cn.kabalifeuser.ui.my.bean.MyUserInfoBean;
import com.cn.kabalifeuser.ui.my.bean.VipInfoBean;
import com.cn.kabalifeuser.ui.my.bean.VipRecommendBean;
import com.cn.kabalifeuser.utils.LoggerUtils;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;

/**
 * Created by 晓林 on 2020/9/25.
 * function:
 */
public class VipPresenter extends BasePresenter<VipView> {

    //推荐
    public void onShoppingMallData(String token,   String is_gift, int page, int limit) {
        OkGo.<ShoppingMalListBean>get(Api.API_INDEX_GOODS_LIST)
                .headers("token", token)
                .params("limit", limit)
                .params("page", page)
                .params("is_gift", is_gift)
                .execute(new CacheCallBack<ShoppingMalListBean>() {
                    @Override
                    public void onSuccess(Response<ShoppingMalListBean> response) {
                        super.onSuccess(response);
                        LoggerUtils.e("list：" + response.body());
                        if (isViewAttached())
                            if (response.body().getCode() == Constants.HTTP_SUCCESS)
                                getView().onShoppingMalListSuccess(response.body());
                            else if (response.body().getCode() == Constants.HTTP_AGAIN_LOGIN)
                                getView().onReLoggedIn(response.body().getMsg());
                            else
                                getView().onError(response.body().getMsg());
                    }
                });
    }

    /**
     *  权益
     * @param token
     */
    public void onVipInfoData(String token) {
        OkGo.<VipInfoBean>get(Api.API_USER_VIP_END)
                .headers("token", token)
                .execute(new CacheCallBack<VipInfoBean>() {
                    @Override
                    public void onSuccess(Response<VipInfoBean> response) {
                        super.onSuccess(response);
                        LoggerUtils.e("权益" + response.body());
                        if (isViewAttached())
                            if (response.body().getCode() == Constants.HTTP_SUCCESS)
                                getView().onVipInfoSuccess(response.body());
                            else if (response.body().getCode() == Constants.HTTP_AGAIN_LOGIN)
                                getView().onReLoggedIn(response.body().getMsg());
                            else
                                getView().onError(response.body().getMsg());
                    }
                });
    }

}
